package com.gome.ss.flowcrawl.extractor;

class BitMap
{
	public byte[] mBitArray;
	public int maxNum = 0;
	public int bitCnt = 0;
	public int total = 0;

	public BitMap(int maxNum)
	{
		this.maxNum = maxNum+1;
		
		bitCnt = this.maxNum/8;
		if(this.maxNum%8>0)
			++bitCnt;
		mBitArray = new byte[bitCnt];
	}

	public int GetBitCount()
	{
		return total;
	}
	public void SetBit(int n)
	{
		if (n > this.maxNum)
			return;
		
		mBitArray[n>>3] |= (1<<(n&7));
		++total;
	}
	
	public byte[] Get()
	{
		return mBitArray;
	}
	
	public static int calc(byte[] a, byte[] b)
	{
		int len = a.length > b.length ? b.length : a.length;
		
		int sc = 0;
		for(int i=0; i<len; ++i)
		{
			for(int j=0; j<8; ++j)
			{
				if(((a[i]&(1<<j)) & (b[i]&(1<<j)))!=0)
				{
					++sc;
				}
			}
		}
		return sc;
	}

	
};
